﻿#region

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Web.Services.Description;
using CuongHanh.Context;
using CuongHanh.Helpers;
using CuongHanh.Models.NotMapDB;
using CuongHanh.Models.View;
using Ext.Net.Utilities;

#endregion

namespace CuongHanh.Models
{
    [Table("tbl_Customer")]
    public class Customer
    {
        public Customer()
        {
        }

        public Customer(CustomerModel model)
        {
            FullName = model.FullName;
            Phone = model.Phone;
            Address = model.Address;
            Email = model.Email;
            Username = model.Username.Trim();
            Password = PasswordHelper.GetPassword(model.Username,
                    model.Password);
            Inactive = false;
            LastModified = DateTime.Now;
        }

        [Key]
        public int Id { get; set; }

        [Required]
        public string FullName { get; set; }

        [Required]
        public string Username { get; set; }

        [Required]
        [DataType(DataType.Password)]
        public string Password { get; set; }

        [Required]
        public string Phone { get; set; }

        [Required]
        [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public string Email { get; set; }

        [Required]
        public string Address { get; set; }

        public string ResetKey { get; set; }

        public DateTime? TimeReset { get; set; }

        public bool Inactive { get; set; }

        public DateTime LastModified { get; set; }

        public void UpdateInfo(Customer model)
        {
            FullName = model.FullName;
            Phone = model.Phone;
            Address = model.Address;
            LastModified = DateTime.Now;
        }
    }
}
